package com.dragon.app.commons.constant;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;

/**
 * 紧急联系人枚举类
 * @author wujunfeng
 *
 */
public enum ContactsTypeEnum {
	
	FATHER("1","父亲"),
	MOTHER("2","母亲"),
	RELATIVES("3","亲人"),
	FRIEND("4","朋友"),
	COLLEAGUE("5","同事"),
	CHILDREN("6","子女");
	
	private String id;
	private String name;
	
	private ContactsTypeEnum(String id, String name) {
		this.id = id;
		this.name = name;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	/**
	 * 获取关系列表
	 * @param type
	 * @return
	 */
	public static List<Map<String, String>> getContactsNameList(){
		List<Map<String, String>> list = new ArrayList<Map<String, String>>();
		for (ContactsTypeEnum e : ContactsTypeEnum.values()) {
			Map<String, String> map = new HashMap<String, String>();
			map.put("id", e.getId());
			map.put("name", e.getName());
			list.add(map);
		}
		return list;
	}
	
	/**
	 * 根据id获取name
	 * @param id
	 * @return
	 */
	public static String getNameById(String id){
		String name = null;
		if(id != null){
			for (ContactsTypeEnum e : ContactsTypeEnum.values()) {
				if(e.getId().equals(id)){
					name = e.getName();
					break;
				}
			}
		}
		return name;
	}
	
	public static void main(String[] args) {
		System.out.println(JSONObject.toJSON(ContactsTypeEnum.getContactsNameList()));;
	}
}
